package com.deeper.customview.ui.c1.demo;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.deeper.customview.BaseFragment;
import com.deeper.customview.R;

public class Chapter01Demo07Fragment extends BaseFragment {

    private ImageView iv;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_chapter01_demo07, container, false);

        iv = root.findViewById(R.id.iv);
        Bitmap bmp = Bitmap.createBitmap(500, 800, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bmp);
        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.RED);
        paint.setAntiAlias(true);
        paint.setStrokeWidth(4);

        Path path = new Path();

        path.moveTo(20, 20);
        path.lineTo(50, 60);
        canvas.drawPath(path, paint);

        float centerX = 200;
        float centerY = 200;
        float radar = 100;

        path.moveTo(centerX, centerY - radar);
        path.lineTo((float) (centerX - radar * Math.sin(Math.toRadians(36.0))), (float) (centerY + radar * Math.cos(Math.toRadians(36.0))));
        path.lineTo((float) (centerX + radar * Math.cos(Math.toRadians(18.0))), (float) (centerY - radar * Math.sin(Math.toRadians(18.0))));
        path.lineTo((float) (centerX - radar * Math.cos(Math.toRadians(18.0))), (float) (centerY - radar * Math.sin(Math.toRadians(18.0))));
        path.lineTo((float) (centerX + radar * Math.sin(Math.toRadians(36.0))), (float) (centerY + radar * Math.cos(Math.toRadians(36.0))));
        path.close();
        paint.setStrokeJoin(Paint.Join.ROUND);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawPath(path, paint);

        path.addCircle(centerX, centerY, radar, Path.Direction.CCW);
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawPath(path, paint);

        iv.setImageBitmap(bmp);

        return root;
    }
}
